package com.gupao.ldr.pattern.observer.guavaapi;

import com.google.common.eventbus.EventBus;

public class GPer {

    private String name="GPer生态圈";
    private static EventBus eventBus=new EventBus();

    private GPer(){
        if (GPerHolder.LAZY != null) {
            throw new RuntimeException("不允许创建多个实例");
        }
    }

    public static GPer getInstance(){
        return GPerHolder.LAZY;
    }

    private static class GPerHolder{
        private static final GPer LAZY=new GPer();
    }

    public void register(Object obj){
        eventBus.register(obj);
    }

    public String getName(){
        return name;
    }
    //发布问题
    public void publish(Question question){
        System.out.println(question.getUserName()+"发布问题到"+this.name);
        //触发修改事件
        eventBus.post(question);
    }

}
